package com.sreader.logic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LetterToDigitMapping {

	private static Map <Integer, List<String>> lettersValuesMap = new HashMap<Integer, List<String>>();
	private static final List <String> LATINVALUESFORONE = new ArrayList<String>(Arrays.asList("A","J","S"));
	private static final List <String> LATINVALUESFORTWO = new ArrayList<String>(Arrays.asList("B","K","T"));
	private static final List <String> LATINVALUESFORTHREE = new ArrayList<String>(Arrays.asList("C","L","U"));
	private static final List <String> LATINVALUESFORFOUR = new ArrayList<String>(Arrays.asList("D","M","V"));
	private static final List <String> LATINVALUESFORFIVE = new ArrayList<String>(Arrays.asList("E","N","W"));
	private static final List <String> LATINVALUESFORSIX = new ArrayList<String>(Arrays.asList("F","O","X"));
	private static final List <String> LATINVALUESFORSEVEN = new ArrayList<String>(Arrays.asList("G","P","Y"));
	private static final List <String> LATINVALUESFOREIGHT = new ArrayList<String>(Arrays.asList("H","Q","Z"));
	private static final List <String> LATINVALUESFORNINE = new ArrayList<String>(Arrays.asList("I","R"));
	
	public LetterToDigitMapping(){
		initLatin();	
	}
	private static void initLatin(){
		LetterToDigitMapping.add(1, LATINVALUESFORONE);
		LetterToDigitMapping.add(2, LATINVALUESFORTWO);
		LetterToDigitMapping.add(3, LATINVALUESFORTHREE);
		LetterToDigitMapping.add(4, LATINVALUESFORFOUR);
		LetterToDigitMapping.add(5, LATINVALUESFORFIVE);
		LetterToDigitMapping.add(6, LATINVALUESFORSIX);
		LetterToDigitMapping.add(7, LATINVALUESFORSEVEN);
		LetterToDigitMapping.add(8, LATINVALUESFOREIGHT);
		LetterToDigitMapping.add(9, LATINVALUESFORNINE);
	}
	
	public static void add(Integer key, String letter){
		List<String> list;
		if(lettersValuesMap.containsKey(key)){
			list = lettersValuesMap.get(key);
			list.add(letter);
		}else{
			list = new ArrayList<String>();
			list.add(letter);
			lettersValuesMap.put(key, list);
		}
	}
	public static void add(Integer key, List<String> list){
		if(!lettersValuesMap.containsKey(key)){
			lettersValuesMap.put(key, list);
		}
	}
	public  int findDigitForLetter(String letter){
		//0 for unknown character for example ""
		int digit = 0;
		for(Integer key: lettersValuesMap.keySet()){
			if(lettersValuesMap.get(key).contains(letter)){
				digit = key;
			}
		}
		return digit;
	}

}
